import http from '@/utils/http/axios'
import { BasicResponseModel } from '@/api/model/baseModel'
import { CaptchaGetParams, CaptchaCheckParams, LoginParams, LoginResultModel } from './model/userModel'

enum Api {
  Login = '/api/code/iu/login', //扫码登陆
  MerchantInfo = '/api/code/info', //登陆信息
  CaptchaGet = '/api/code/iu/captcha', //获取图形验证码
  CaptchaCheck = '/api/code/iu/check' //验证图形验证码
}

/**
 * @description: 获取用户信息
 */
export function getUserInfo() {
  return http.request({
    url: Api.MerchantInfo,
    method: 'GET'
  })
}

/**
 * @description: 校验token失效
 */
export function checkToken() {
  return http.request({
    url: '/api/account/merchant/login/check/token',
    method: 'POST'
  })
}

/**
 * @description: 用户登录
 */
export function login(params: LoginParams) {
  return http.request<BasicResponseModel<LoginResultModel>>({
    url: Api.Login,
    method: 'POST',
    params
  })
}

/**
 * @description: 获取图形验证码
 */
export function captchaGet(params: CaptchaGetParams) {
  return http.request({
    url: Api.CaptchaGet,
    method: 'POST',
    params
  })
}

/**
 * @description: 图形验证码验证
 */
export function captchaCheck(params: CaptchaCheckParams) {
  return http.request(
    {
      url: Api.CaptchaCheck,
      method: 'POST',
      params
    },
    {
      isTransformResponse: false
    }
  )
}
